package implementor;

import java.sql.SQLException;

import utility.AppUtilities;

import model.GinItems;
import model.IssueSlipItem;

import dao.GinDao;
import dao.GinItemsDao;
import dao.IssueSlipItemDao;
import dbhandelling.Crude;
import dto.Gin;

public class GinImplementor extends Crude implements GinDao
{
	String className=new Gin().getClass().getName();
	@Override
	public void add(Gin gin) throws Exception 
	{
		insert(gin);
	}

	@Override
	public void update(Gin gin) throws Exception 
	{
		super.update(className,"status" ,gin.getStatus()+"", "ginNo",gin.getAutoginNo()+"");
	}

	@Override
	public void delete(Gin gin) throws Exception 
	{
		super.delete(className,"ginNo",gin.getAutoginNo()+"");
	}

	@Override
	public Gin retreive(String conditionField, String ConditionValue) throws Exception 
	{
		Gin gin=(Gin) super.retreive(className,conditionField, ConditionValue);
		GinItemsDao ginItems =new GinItemsImplementor();
		GinItems[] allItems = ginItems.retreiveArray("ginNo",gin.getAutoginNo()+"");
		gin.setModelginitems(allItems);
		gin.setModelprojectName(AppUtilities.getProjectName(gin.getIdProject()));
		return gin;
	}

	@Override
	public Gin[] retreiveArray(String conditionField, String conditionValue) throws Exception 
	{
		Gin[] gins;
		Object[] obj=super.retreiveArrayOnCondition(className, conditionField, conditionValue);
		gins=new Gin[obj.length];
		
		for(int i=0;i<gins.length;i++)
		{
			gins[i]=(Gin) obj[i];
		}
		
		return gins;
	}

	@Override
	public Gin[] retreiveAll() throws Exception 
	{
		Gin[] gins;
		
		Object[] obj=super.retreiveAll(className);
		
		gins=new Gin[obj.length];
		
		for(int i=0;i<gins.length;i++)
		{
			gins[i]=(Gin) obj[i];
		}
		
		return gins;
	}
   
	@Override
	public int getautoginNo() {
		int x=super.getAutoGenratedKey(className,"autoginNo");
		return x;
	}
	
	
	
	

}
